package com.lagou;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @author lcy
 * @description TODO
 * @date 2020/11/11 22:25
 * @vserion 1.3.3
 */
@Activate(group = CommonConstants.PROVIDER)
public class DubboInvokeFilter implements Filter {
	@Override
	public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
		long   startTime  = System.currentTimeMillis();
		try {
			// 增加获取IP代码逻辑
			String remoteIp = RpcContext.getContext().getRemoteHost();
			System.out.println("输出请求的IP"+remoteIp);
			// 执行方法
			return  invoker.invoke(invocation);
		} finally {
			System.out.println("invoke time:"+(System.currentTimeMillis()-startTime) + "毫秒");
		}
	}
}
